﻿using Dapper;
using HR.IServices.PengIService;
using HR.Models.PengModels;
using System.Data.SqlClient;

namespace HR.Services.PengService
{
    public class Two_kindServices : ITwo_kindServices
    {
        private readonly IConfiguration conf;
        private readonly string? conStr;

        public Two_kindServices(IConfiguration conf)
        {
            this.conf = conf;
            conStr = this.conf["ConnectionStrings"];
        }
        public Task<int> Add(Two_kind two_Kind)
        {
            return Task.Run(() =>
            {
                using (SqlConnection con = new SqlConnection(conStr))
                {
                    return con.Execute($"insert into config_file_second_kind(first_kind_id, first_kind_name, second_kind_id, second_kind_name, second_salary_id, second_sale_id) values('{two_Kind.First_kind_id}','{two_Kind.First_kind_name}','{two_Kind.Second_kind_id}','{two_Kind.Second_kind_name}','{two_Kind.Second_salary_id}','{two_Kind.Second_sale_id}')");
                }
            });
        }

        public Task<int> Delete(int fsk_id)
        {
            return Task.Run(() =>
            {
                using (SqlConnection con = new SqlConnection(conStr))
                {
                    return con.Execute($"delete from config_file_second_kind where fsk_id = '{fsk_id}'");
                }
            });
        }

        public Task<List<Two_kind>> FindAll()
        {
            return Task.Run(() =>
            {
                using (SqlConnection con = new SqlConnection(conStr)) 
                {
                    return con.Query<Two_kind>($"select * from config_file_second_kind").ToList();
                }
            });
        }

        public Task<List<First_kind>> FirstName()
        {
            return Task.Run(() =>
            {
                using (SqlConnection con = new SqlConnection(conStr))
                {
                    return con.Query<First_kind>($"select first_kind_id,first_kind_name from config_file_first_kind").ToList();
                }
            });
        }

        public Task<int> Update(Two_kind two_Kind)
        {
            return Task.Run(() =>
            {
                using (SqlConnection con = new SqlConnection(conStr))
                {
                    return con.Execute($"update config_file_second_kind set first_kind_id = '{two_Kind.First_kind_id}',first_kind_name ='{two_Kind.First_kind_name}',second_kind_id ='{two_Kind.Second_kind_id}',second_kind_name ='{two_Kind.Second_kind_name}',second_salary_id ='{two_Kind.Second_salary_id}',second_sale_id = '{two_Kind.Second_sale_id}' where fsk_id = '{two_Kind.Fsk_id}'");
                }
            });
        }
    }
}
